/////////////////////////////////////////////////////////////////////////////
/*/	
 *	Creator:		Joshua C. Rouzer
 *	Title:			Moving Object cpp
 *	Last Edited:	06/14/2013
 *	Summary:		Function definition for moving class units
/*/
/////////////////////////////////////////////////////////////////////////////
#include "MovingObject.h"
#include <math.h>
/////////////////////////////////////////////////////////////////////////////
// Function : Default constructor
// Notes	: Assigns base values to the object
/////////////////////////////////////////////////////////////////////////////
CMovingObject::CMovingObject()
{
	m_eType = MOVING;
	m_fVelX = 0.0f;
	m_fVelY = 0.0f;
	m_nPath = 0;
}
/////////////////////////////////////////////////////////////////////////////
// Function		: Destructor
// Notes		: Cleans up any and all dynamically allocated memory
/////////////////////////////////////////////////////////////////////////////
CMovingObject::~CMovingObject(){}
/////////////////////////////////////////////////////////////////////////////
// Function		: Update
// Parameters	: dT - Time elapsed since last update
// Notes		: Updates the position variables based on the velocity
//					and elapsed time
/////////////////////////////////////////////////////////////////////////////
void CMovingObject::Update(float dT){
	SetPosX(GetPosX() + (m_fVelX * dT));
	SetPosY(GetPosY() + (m_fVelY * dT));
}
/////////////////////////////////////////////////////////////////////////////
// Function		: Render
// Notes		: Renders the object to the screen
/////////////////////////////////////////////////////////////////////////////
void CMovingObject::Render(){
	CBaseClass::Render();
}
/////////////////////////////////////////////////////////////////////////////
// Function		: Check Collision
// Parameters	: check - The object to check collision with
// Return		: whether the objects collided or not
// Notes		: Uses the GetRect function to check for collision
//					Then will send a message of collision through
//					the message system to any listeners
/////////////////////////////////////////////////////////////////////////////
bool CMovingObject::CheckCollision(CBaseClass *check){
	RECT rect, checkRect, overlap;
	rect = this->GetRect();
	checkRect = check->GetRect();
	if(IntersectRect(&overlap, &rect, &checkRect) == FALSE){
		return false;
	}
	//Create message to be sent here

	return true;
}

int CMovingObject::DistanceBetween(SPosition one, SPosition two)
{
	float x2 = (two.m_nPosX - one.m_nPosX) * (two.m_nPosX - one.m_nPosX);
	float y2 = (two.m_nPosY - one.m_nPosY) * (two.m_nPosY - one.m_nPosY);
	float d = sqrt(x2 + y2);

	return (int)d;
}
